package com.wuming.caiwu.service.impl;

import com.wuming.caiwu.core.BusinessException;
import com.wuming.caiwu.core.WumingErrorCode;
import com.wuming.caiwu.dao.QsgJoinMapper;
import com.wuming.caiwu.model.QsgJoin;
import com.wuming.caiwu.service.QsgJoinService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class QsgJoinServiceImpl extends BaseServiceImpl implements QsgJoinService {

    @Override
    public List<QsgJoin> getQsgJoinByPage(String startDate, String endDate, int pageIndex, int pageSize) throws BusinessException {
        Map<String,Object> params = new HashMap<>();
        if(StringUtils.isNotBlank(startDate)){
            params.put("startDate",startDate + " 00:00:00");
        }
        if(StringUtils.isNotBlank(endDate)){
            params.put("endDate",endDate + " 23:59:59");
        }
        try{
            return (List<QsgJoin>) this.getPageList(QsgJoinMapper.class, "selectByParams", params, pageIndex, pageSize);
        }catch(Exception e) {
            logger.error("查询加盟商信息失败{}" + e.getMessage());
            throw new BusinessException(WumingErrorCode.HUIQIAN_USERCENTER_DATABASE_OPERATE_ERROR);
        }
    }

    @Override
    public int getTotal(String startDate, String endDate) throws BusinessException {
        Map<String,Object> params = new HashMap<>();
        if(StringUtils.isNotBlank(startDate)){
            params.put("startDate",startDate + " 00:00:00");
        }
        if(StringUtils.isNotBlank(endDate)){
            params.put("endDate",endDate + " 23:59:59");
        }
        try{
            return this.getTotal(QsgJoinMapper.class, "selectTotal", params);
        }catch(Exception e) {
            logger.error("查询加盟商总数失败{}" + e.getMessage());
            throw new BusinessException(WumingErrorCode.HUIQIAN_USERCENTER_DATABASE_OPERATE_ERROR);
        }
    }
}
